﻿@model PagedList.IPagedList<BookShop3Tables.Models.Category>

@{
    ViewBag.Title = "Genre";
}

<h2>Genres</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm())
{
    <p>
        Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)  
        <input type="submit" value="Search" /></p>
}
<table>
    <tr>
        <th>
           @Html.ActionLink("Name", "Index", new { sortOrder=ViewBag.NameSortParm, currenyFilter = ViewBag.CurrentFilter })
        </th>
        <th>
            Number of Books
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) 
{
    string selectedRow = "";
    if (item.CategoryID == ViewBag.CategoryID)
    {
        selectedRow = "selectedrow";
    }
    <tr class ="@selectedRow" valign ="top">
        <td>
            @item.Name
        </td>
        <td>
            @item.Books.Count
        </td>
        <td>
            @Html.ActionLink("Select", "Index", new { id = item.CategoryID})|
            @Html.ActionLink("Edit", "Edit", new { id=item.CategoryID }) |
            @Html.ActionLink("Details", "Details", new { id=item.CategoryID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.CategoryID })
        </td>
    </tr>
}

</table>

<div>
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    of @Model.PageCount
     
    @if (Model.HasPreviousPage)
    {
        @Html.ActionLink("<<", "Index", new { page = 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
        @Html.Raw(" ");
        @Html.ActionLink("< Prev", "Index", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
    }
    else
    {
        @:<<
        @Html.Raw(" ");
        @:< Prev
    }
     
    @if (Model.HasNextPage)
    {
        @Html.ActionLink("Next >", "Index", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
        @Html.Raw(" ");
        @Html.ActionLink(">>", "Index", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
    }
    else
    {
        @:Next >
        @Html.Raw(" ")
        @:>>
    }
</div>
